﻿using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Com.Seezt.Skins;
using Components;
using Controls;
using UI.Lib;
using UI.Lib.Factory;
using UI.ParentForm;

namespace UI.Invoice
{
    public partial class FrmTic1a10Query : BaseQuery
    {
        public FrmTic1a10Query(string modulecode, string action) :
            base(modulecode, action)
        {
            InitializeComponent();
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }

            if ("shopcode" == name)
            {
                var sellerid = Validation.ToString(this.tbSummary.GetValue("cesellerid"));
                if (string.IsNullOrEmpty(sellerid))
                {
                    MessageBox.Show("请先选择销售商！", "提示");
                    this.tbSummary.Focus("sellercode");
                    return false;
                }

                where = string.Format("slistid = '{0}' {1} ", sellerid, Context.GetAppKeyWhere("muser", true));
            }
            else if ("subcode" == name)
            {
                where = string.Format("substatue = '1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }

            return true;
        }

        protected override void DoSearch()
        {
            Hashtable where = new Hashtable();
            where["cesellerid"] = Validation.ToString(this.tbSummary.GetValue("cesellerid")); 
            where["start"] = Validation.ToDate(this.tbSummary.GetValue("start"), Global.MinDate); //控件ID
            where["end"] = Validation.ToDate(this.tbSummary.GetValue("end"), Global.MaxDate); //结束日期
            where["ceshopid"] = Validation.ToString(this.tbSummary.GetValue("ceshopid"));
            where["cedono"] = Validation.ToString(this.tbSummary.GetValue("cedono"));
            where["cesubtype"] = Validation.ToString(this.tbSummary.GetValue("cesubtype"));
            where["cesubid"] = Validation.ToString(this.tbSummary.GetValue("cesubid"));

            DataTable dt = CommonHelper.Entity.ExecFun("gettic1a10query", where);

            BinderGrid(dt);
        }
    }
}
